package com.site_assembly.apiImpl;

import com.service.WareHousingApiService;
import com.service.form.WarehousingForm;
import com.site_assembly.entity.Warehousing;
import com.site_assembly.service.IWarehousingService;
import com.util.Result;
import com.zsd.apiService.StorageApi;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@Slf4j
@Api(tags = "子站点端（废品入库管理）接口", description = "提供子站点（废品入库管理）相关的 Rest API")
public class WareHousingApiImpl implements WareHousingApiService {

    @Resource
    private IWarehousingService warehousingService;

    @Resource
    private StorageApi storageApi;

    @Override
    @ApiOperation("废品入库录入")
    @ApiResponses({@ApiResponse(code = 20000, message = "录入成功"), @ApiResponse(code = 40000, message = "录入失败")})
    public Result wasteWareHousing(@Valid WarehousingForm warehousingForm) {


        log.info("入库信息{}", warehousingForm);
        Warehousing warehousing = new Warehousing();
        BeanUtils.copyProperties(warehousingForm, warehousing);
        warehousingService.wasteWareHousing(warehousing);
        //修改仓库容量
        storageApi.setStorageCapacityByStorageId(warehousingForm.getInWeight(), warehousingForm.getStorageId());

        return Result.success();
    }
}
